package com.yanqu.road.server.cmd.building;

import com.yanqu.road.pb.building.BuildingProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BuildingModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Cmd(code = Protocol.S_BUILDING_DISPATCH_PATRONS, desc = "店铺派遣门客")
public class BuildingDispatchPatronsCmd extends AbstractCommand {

	protected static Logger log = LogManager.getLogger(BuildingDispatchPatronsCmd.class.getName());

	private List<Integer> patronsIdList;

	private int buildingId;

	private int operate;
	private List<BuildingProto.BuildingDispatchPatronsData> changeListList;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		BuildingProto.BuildingDispatchPatronsNewReqMsg reqMsg = BuildingProto.BuildingDispatchPatronsNewReqMsg.parseFrom(packet.getBytes());
		buildingId = reqMsg.getBuildingId();
		patronsIdList = new ArrayList<>();
		changeListList = reqMsg.getChangeListList();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(BuildingModule.class).dispatchPatrons(buildingId, changeListList);
	}

	@Override
	public void sendData(GamePlayer player) {
		BuildingProto.BuildingRespMsg.Builder respMsg = BuildingProto.BuildingRespMsg.newBuilder();
		respMsg.setRet(ret);
		player.sendPacket(Protocol.U_BUILDING_DISPATCH_PATRONS, respMsg);
	}

}
